package com.longjianghuasheng.logistics.business.billing_period.fragment

import android.os.Bundle
import android.view.View
import androidx.core.view.isGone
import androidx.core.view.isVisible
import com.longjianghuasheng.logistics.BR
import com.longjianghuasheng.logistics.R
import com.longjianghuasheng.logistics.base.BaseTitleFragment
import com.longjianghuasheng.logistics.databinding.FragmentAccountOpeningBinding
import com.longjianghuasheng.logistics.ext.observer
import com.xuexiang.xui.widget.banner.widget.banner.BannerItem
import me.hgj.jetpackmvvm.ext.view.visible

class AccountOpeningFragment :
    BaseTitleFragment<AccountOpeningViewModel, FragmentAccountOpeningBinding>() {

    override fun initViewModelId(): Int = BR.accountOpeningViewModel
    override fun layoutId(): Int = R.layout.fragment_account_opening

    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)
        initTitleBar("账期")

    }

    override fun createObserver() {
        super.createObserver()
        mViewModel.result.observer(this) {
            navigateUp()
        }
        mViewModel.bannerResult.observer(this) {
            mDatabind.setData(it)
            mViewModel.account_data()
        }
        mViewModel.accountResult.observer(this) {

            mDatabind.tvMoney.text = it.account
        }
    }

    override fun initData() {
        super.initData()
        mViewModel.isAccount = arguments?.getBoolean("isAccount") ?: false

        mDatabind.run {

            llApplyFor.isGone = mViewModel.isAccount
            clBalance.isVisible = mViewModel.isAccount
        }
    }

    private fun FragmentAccountOpeningBinding.setData(arrayList: ArrayList<String>) {

        banner.setSource(arrayList.map {

            BannerItem().apply {
                imgUrl = it
            }

        })
            .setOnItemClickListener { view: View?, t: BannerItem?, position: Int -> }
            .setIsOnePageLoop(false).startScroll()
        llContainer.visible()
    }

    override fun lazyLoadData() {
        super.lazyLoadData()
        mViewModel.banner()
    }


}